from django.shortcuts import render
from django.http import HttpResponse,Http404
from myadmin.models import Cates,Goods
from . import common

# Create your views here.
def index(request):
    data=dict()
    data['nav']= common.left()
    data['offprice'] = Goods.objects.filter(status=1)[:3]
    data['hot']= Goods.objects.filter(status=2)[:8]

    return render(request,'myhome/index/index.html',data)

def fruits(request):
    data = dict()
    data['nav'] = common.left()
    return render(request,"myhome/index/fruits.html",data)


def products(request):
    data = dict()
    data['nav'] = common.left()
    return render(request,"myhome/index/products.html",data)


def store(request):
    data = dict()
    data['nav'] = common.left()
    return render(request,"myhome/index/store.html",data)


def club(request):
    data = dict()
    data['nav'] = common.left()
    return render(request,"myhome/index/club.html",data)


def contact(request):
    data = dict()
    data['nav'] = common.left()
    return render(request,"myhome/index/contact.html",data)


def mylist(request,cid):
    data = dict()
    data['nav'] = common.left()
    return render(request,"myhome/index/mylist.html",data)


def article(request):
    data = dict()
    data['nav'] = common.left()
    data['offprice'] = Goods.objects.filter(status=1)[:3]
    try:
        # 根据商品id获取商品数据
        ob = Goods.objects.get(id=request.GET.get('gid'))
        # 分配数据
        data['goods'] = ob
        # 加载模板
        return render(request, "myhome/index/single.html", data)
    except:
        pass

    raise Http404('您需要的页面找不到了...')




